/*
 * Copyright (c) 2017. 深圳掌控网络有限公司. All rights reserved.
 */

package com.yiqi.lottery.feature.mine.presenter;

import com.suozhang.framework.entity.bo.PageData;
import com.yiqi.lottery.entity.bo.CharsBo;
import com.yiqi.lottery.entity.bo.OrderListBo;
import com.yiqi.lottery.feature.lottery.dependencies.order.DaggerOrderPresenterComponent;
import com.yiqi.lottery.feature.mine.contract.NumberContract;
import com.yiqi.lottery.feature.mine.contract.OrderContract;
import com.yiqi.lottery.feature.mine.dependencies.number.DaggerNumberPresenterComponent;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

import javax.inject.Inject;

/**
 *      LIJUWEN
 * @email yiyayiyayaoljw@gmail.com
 * @date 2017/4/11 9:31
 */
public class NumberPresenter implements NumberContract.Presenter {

    private NumberContract.View mView;

    @Inject

    NumberContract.Model mModel;


    public NumberPresenter(NumberContract.View mView) {
        this.mView = mView;
        DaggerNumberPresenterComponent.create().inject(this);
    }


    @Override
    public void getMyCharsList(int page) {
        mModel.getMyCharsList(page).compose(mView.bindToLife()).subscribe(new Observer<PageData<CharsBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(PageData<CharsBo> s) {
                mView.dismissLoading();

                if (s.getList().size() > 0) {
                    mView.showMyBanlanceSuccess(s);
                } else {
                    mView.showMyBanlanceEmpty();
                }
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showMyBanlanceError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void getMyCharsMoreList(int page) {
        mModel.getMyCharsList(page).compose(mView.bindToLife()).subscribe(new Observer<PageData<CharsBo>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(PageData<CharsBo> s) {
             mView.showMyBanlanceMoreSuccess(s);
            }

            @Override
            public void onError(Throwable e) {
              mView.showMyBanlanceMoreError(e.getMessage());
            }

            @Override
            public void onComplete() {
            }
        });
    }

    @Override
    public void getMyCharsDetail(int id) {
        mModel.getMyCharsDetail(id).compose(mView.bindToLife()).subscribe(new Observer<CharsBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(CharsBo charsBo) {
                  mView.dismissLoading();
                mView.showNumberDetailSuccess(charsBo);
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showMyBanlanceError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void start() {

    }


}
